from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-05 14:05:42.351916
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 05, May, 2021
Time: 14:05:47
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.0119
Nobs: 282.000 HQIC: -48.7081
Log likelihood: 3422.29 FPE: 4.40604e-22
AIC: -49.1742 Det(Omega_mle): 3.21992e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.411734 0.118311 3.480 0.001
L1.Burgenland 0.069566 0.059314 1.173 0.241
L1.Kärnten -0.225296 0.052784 -4.268 0.000
L1.Niederösterreich 0.100560 0.127536 0.788 0.430
L1.Oberösterreich 0.221658 0.123344 1.797 0.072
L1.Salzburg 0.274396 0.067871 4.043 0.000
L1.Steiermark 0.111261 0.086585 1.285 0.199
L1.Tirol 0.120022 0.060015 2.000 0.046
L1.Vorarlberg -0.032702 0.055063 -0.594 0.553
L1.Wien -0.042493 0.110763 -0.384 0.701
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.433261 0.136554 3.173 0.002
L1.Burgenland 0.002786 0.068460 0.041 0.968
L1.Kärnten 0.328908 0.060924 5.399 0.000
L1.Niederösterreich 0.117813 0.147202 0.800 0.424
L1.Oberösterreich -0.069253 0.142364 -0.486 0.627
L1.Salzburg 0.226908 0.078337 2.897 0.004
L1.Steiermark 0.090098 0.099937 0.902 0.367
L1.Tirol 0.136073 0.069269 1.964 0.049
L1.Vorarlberg 0.151806 0.063553 2.389 0.017
L1.Wien -0.409161 0.127843 -3.200 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.256442 0.060119 4.266 0.000
L1.Burgenland 0.104671 0.030140 3.473 0.001
L1.Kärnten -0.013877 0.026822 -0.517 0.605
L1.Niederösterreich 0.091934 0.064806 1.419 0.156
L1.Oberösterreich 0.282801 0.062676 4.512 0.000
L1.Salzburg 0.020722 0.034488 0.601 0.548
L1.Steiermark -0.000788 0.043997 -0.018 0.986
L1.Tirol 0.067499 0.030496 2.213 0.027
L1.Vorarlberg 0.075599 0.027980 2.702 0.007
L1.Wien 0.116877 0.056283 2.077 0.038
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211936 0.057400 3.692 0.000
L1.Burgenland 0.027845 0.028777 0.968 0.333
L1.Kärnten 0.009345 0.025609 0.365 0.715
L1.Niederösterreich 0.054035 0.061875 0.873 0.383
L1.Oberösterreich 0.395100 0.059841 6.602 0.000
L1.Salzburg 0.080071 0.032928 2.432 0.015
L1.Steiermark 0.132807 0.042008 3.161 0.002
L1.Tirol 0.050484 0.029117 1.734 0.083
L1.Vorarlberg 0.081098 0.026714 3.036 0.002
L1.Wien -0.043302 0.053738 -0.806 0.420
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.454443 0.112579 4.037 0.000
L1.Burgenland 0.101350 0.056440 1.796 0.073
L1.Kärnten 0.008954 0.050227 0.178 0.859
L1.Niederösterreich 0.020652 0.121357 0.170 0.865
L1.Oberösterreich 0.120236 0.117368 1.024 0.306
L1.Salzburg 0.058598 0.064583 0.907 0.364
L1.Steiermark 0.068784 0.082390 0.835 0.404
L1.Tirol 0.201213 0.057107 3.523 0.000
L1.Vorarlberg 0.035683 0.052395 0.681 0.496
L1.Wien -0.064304 0.105397 -0.610 0.542
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.213079 0.088600 2.405 0.016
L1.Burgenland -0.011726 0.044418 -0.264 0.792
L1.Kärnten -0.006324 0.039529 -0.160 0.873
L1.Niederösterreich -0.015977 0.095508 -0.167 0.867
L1.Oberösterreich 0.417228 0.092369 4.517 0.000
L1.Salzburg 0.012157 0.050827 0.239 0.811
L1.Steiermark -0.026532 0.064841 -0.409 0.682
L1.Tirol 0.161765 0.044943 3.599 0.000
L1.Vorarlberg 0.057757 0.041235 1.401 0.161
L1.Wien 0.204381 0.082947 2.464 0.014
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211764 0.107538 1.969 0.049
L1.Burgenland 0.021708 0.053913 0.403 0.687
L1.Kärnten -0.072287 0.047978 -1.507 0.132
L1.Niederösterreich -0.056633 0.115923 -0.489 0.625
L1.Oberösterreich 0.016041 0.112112 0.143 0.886
L1.Salzburg 0.086046 0.061691 1.395 0.163
L1.Steiermark 0.323814 0.078701 4.114 0.000
L1.Tirol 0.460482 0.054550 8.441 0.000
L1.Vorarlberg 0.144946 0.050049 2.896 0.004
L1.Wien -0.133154 0.100677 -1.323 0.186
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.204357 0.128503 1.590 0.112
L1.Burgenland 0.040346 0.064423 0.626 0.531
L1.Kärnten -0.074415 0.057331 -1.298 0.194
L1.Niederösterreich 0.116680 0.138523 0.842 0.400
L1.Oberösterreich 0.013700 0.133969 0.102 0.919
L1.Salzburg 0.193626 0.073718 2.627 0.009
L1.Steiermark 0.131098 0.094044 1.394 0.163
L1.Tirol 0.055157 0.065185 0.846 0.397
L1.Vorarlberg 0.106610 0.059806 1.783 0.075
L1.Wien 0.220724 0.120305 1.835 0.067
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.520160 0.071212 7.304 0.000
L1.Burgenland -0.014434 0.035701 -0.404 0.686
L1.Kärnten -0.016990 0.031771 -0.535 0.593
L1.Niederösterreich 0.101896 0.076765 1.327 0.184
L1.Oberösterreich 0.307496 0.074242 4.142 0.000
L1.Salzburg 0.018047 0.040852 0.442 0.659
L1.Steiermark -0.043993 0.052116 -0.844 0.399
L1.Tirol 0.079222 0.036124 2.193 0.028
L1.Vorarlberg 0.102099 0.033143 3.081 0.002
L1.Wien -0.050164 0.066669 -0.752 0.452
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.160713 0.091138 0.166398 0.219040 0.077311 0.085372 0.000592 0.160765
Kärnten 0.160713 1.000000 0.056171 0.211952 0.186105 -0.066067 0.177745 0.021088 0.306787
Niederösterreich 0.091138 0.056171 1.000000 0.242304 0.095409 0.318118 0.148752 0.025825 0.318399
Oberösterreich 0.166398 0.211952 0.242304 1.000000 0.300193 0.259908 0.101307 0.061130 0.139951
Salzburg 0.219040 0.186105 0.095409 0.300193 1.000000 0.149320 0.065588 0.090878 0.024670
Steiermark 0.077311 -0.066067 0.318118 0.259908 0.149320 1.000000 0.093817 0.100462 -0.099893
Tirol 0.085372 0.177745 0.148752 0.101307 0.065588 0.093817 1.000000 0.152557 0.157398
Vorarlberg 0.000592 0.021088 0.025825 0.061130 0.090878 0.100462 0.152557 1.000000 -0.009060
Wien 0.160765 0.306787 0.318399 0.139951 0.024670 -0.099893 0.157398 -0.009060 1.000000